﻿using System;
using ProjectDanmaku.Data;
using UnityEditor;
using UnityEngine;

namespace Editor.ProjectDanmaku.EditorWindow
{
    public class EntityLayerBitManagementWindow : UnityEditor.EditorWindow
    {
        [SerializeField] private EntityLayerBitSettings settingsAsset;
        
        private SerializedObject serializedObject;
        
        [MenuItem("Entity Layer/Entity Layer Bit Management")]
        private static void ShowWindow()
        {
            var window = GetWindow<EntityLayerBitManagementWindow>();
            window.titleContent = new GUIContent("Entity Layer Bit Management");
            window.Show();
        }

        private void OnEnable()
        {
            serializedObject = new SerializedObject(settingsAsset);
        }

        private void OnGUI()
        {
            serializedObject.Update();

            var prop = serializedObject.FindProperty("layerBitNames");
            
            EditorGUILayout.PropertyField(prop);

            serializedObject.ApplyModifiedProperties();
            if (serializedObject.ApplyModifiedProperties())
            {
                EditorUtility.SetDirty(settingsAsset);
            }
        }
    }
}